package com.hbpu.encap.homework;

//定义一个Person类{name, age, job},初始化Person对象数组，有三个Person对象，并按照age从大到小
//进行排序，使用冒泡排序
public class Homework01 {
    public static void main(String[] args) {
        Person[] people = new Person[3];
        people[0] = new Person("make", 20, "老师");
        people[1] = new Person("jack", 53, "老师");
        people[2] = new Person("mike", 34, "老师");
        for (int i = 0; i < people.length - 1; i++) {
            for (int j = 0; j < people.length - 1 - i; j++) {
                if (people[j].getAge() < people[j + 1].getAge()) {
                    Person[] temp = new Person[1];
                    temp[0] = people[j];
                    people[j] = people[j + 1];
                    people[j + 1] = temp[0];
                }
            }
        }
        for (int i = 0; i < people.length; i++) {
            System.out.println(people[i]);
        }
    }
}

class Person {
    private String name;
    private int age;
    private String job;

    public Person(String name, int age, String job) {
        this.name = name;
        this.age = age;
        this.job = job;
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", job='" + job + '\'' +
                '}';
    }
}
